<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of productForm
 *
 * @author sammerelaraby
 */
class APP_Form_ProductForm extends Zend_Form{
    //put your code here
    public function init()
    {
        $prodname=new Zend_Form_Element_Text('prodname');
        $prodname->setRequired(true)
                ->setLabel('Product Name')
                ->addValidator('NotEmpty')
                ->addValidator('StringLength',true,array('min'=>3,'max'=>16))
                ->addValidator('Alnum',true);
        $this->addElement($prodname);

        $prodprice=new Zend_Form_Element_Text('prodprice');
        $prodprice->setRequired(true)
                ->setLabel('Price')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->addValidator('regex',false,array('/[0-9]+/'));
        $this->addElement($prodprice);

        $prodquan=new Zend_Form_Element_Text('prodquan');
        $prodquan->setRequired(true)
                ->setLabel('Quantity')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->addValidator('regex',false,array('/[0-9]+/'));
        $this->addElement($prodquan);


        $cats=new Zend_Db_Table('category');
        $catsQuery=$cats->fetchAll();
        foreach ($catsQuery as $value)
        {
            $value=$value['category_name'];
            $cat[$value]=$value;
        }

        $prodcat=new Zend_Form_Element_Select('catselect',array('multiple'=>false,'label'=>'Category'));
        $prodcat->setIsArray(true);
        $prodcat->setMultiOptions($cat);
        $this->addElement($prodcat);

        $prodimg=new Zend_Form_Element_File('prodimg');
        $prodimg->setLabel('Upload photo')
                    ->setDestination('prodimages')
                    ->setRequired(true)
                    ->addValidator('Count',false,1)
                    ->addValidator('Extension',false,'jpg,png,gif');
            $this->addElement($prodimg);

        $this->addElement('submit','submit',array('ignore'=>true,
            'label'=>'Save',));

        
        $this->setMethod('post')
             ->setName('prodform');
       
    }
}
?>
